<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // Promise.any
    // 也是接受一个由promise对象组成的数组作为参数
    // 但凡由一个成功就成功，并且返回那个第一个成功的结果
    // 如果所有都失败，才失败。并且返回AggregateError: All promises were rejected


    const p1 = new Promise((resolve, reject) => {
      setTimeout(() => {
        let count = -3;
        if (count >= 0) {
          resolve("p1 成功了")
        } else {
          reject("p1 失败了")
        }
      }, 2000)
    })

    const p2 = new Promise((resolve, reject) => {
      setTimeout(() => {
        let num = -3;
        if (num >= 0) {
          resolve("p2 成功了")
        } else {
          reject("p2 失败了")
        }
      }, 4000)
    })

    Promise.any([p1, p2]).then(res => {
      console.log(res); // 但凡由一个成功就走这里
    }).catch(err => {
      console.log(err); // AggregateError: All promises were rejected
    })
  </script>
</body>
</html>